package hv.fmw.mvc.view {
	import hv.fmw.mvc.model.ModelEvent;
	import hv.fmw.mvc.model.Model;

	public class ViewManager {
		
		private static var _instance:ViewManager;
		private var _views : Array = [];
		private var _model : Model;
		
		public function  ViewManager(enforcer:SingletonEnforcer){
			
		}
		
		public function init(model:Model) : void {
			_model = model;
		}
		
		public static function getInstance(): ViewManager{
			if(_instance == null)_instance = new  ViewManager(new SingletonEnforcer());
			return _instance;
		}
		
		public function addView(view:AbstractView) : void {
			_views.push(view);
			view.dispatchEvent(new ModelEvent(ModelEvent.MODEL_READY, _model));
		}
		
		/*
		 * Resize : Call resize method on all views which implementd IResizable
		 */
		public function resize() : void {
			var l:int = _views.length;
			var view:IResizable;
			for(var i:int=0; i<l; i++){
				view = _views[i] as IResizable;
				if(view is IResizable) view.resize();
			}
		}
	}
}

internal class SingletonEnforcer{}